import scrapy

from scrapy_movie_Dome.items import ScrapyMovieDomeItem


class MoviesSpider(scrapy.Spider):
    name = "movies"
    allowed_domains = ["dytt.dytt8.net"]
    start_urls = ["https://dytt.dytt8.net/index.htm"]

    def parse(self, response):
        a_list=response.xpath('//div[@class="co_content8"]//td[1]//a[2]')
        for a in a_list:
            name = a.xpath('./text()').extract_first().replace(' ','')
            href=a.xpath('./@href').extract_first()
            #第二页的url地址
            url='https://dytt.dytt8.net/'+href
            #对第二页进行parse
            yield scrapy.Request(url,callback=self.parse_two,meta={'name':name})
            #通过meta属性进行传参
            # print(url)
            # print(name,href)
    def parse_two(self,response):
        # //div[@id="Zoom"]//img/@src
        src=response.xpath('//div[@id="Zoom"]//img/@src').extract_first()
        name=response.meta['name']
        # print(src)
        movie=ScrapyMovieDomeItem(src=src,name=name)
        yield movie